package cn.itsource.pethome.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 微信登录相关的配置
 */
@Component//交给spring容器管理
public class WxConfig {
    @Value("${appid}")
    private String appid;
    @Value("${secret}")
    private String secret;

    private String access_token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code";
    private String userinfo_url = "https://api.weixin.qq.com/sns/userinfo?access_token=ACCESS_TOKEN&openid=OPENID";

    public String getAccessTokenUrl(String code){
        return access_token_url.replace("APPID",appid)
                         .replace("SECRET",secret)
                        .replace("CODE",code);
    }

    public String getUserinfoUrl(String token,String openid){
        return userinfo_url.replace("ACCESS_TOKEN",token)
                .replace("OPENID",openid);
    }
}
